<template>
  <div>
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable @clear="clearEvent"></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
        <!-- <el-col :span="2">
          <div class="SearchLable">
            <el-button
              size="medium"
              type="primary"
            >添加新药</el-button>
          </div>
        </el-col>-->
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="tableData"
          border
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          style="width: 100%;font-size:12px"
        >
          <el-table-column prop="drugCode" label="药品编码" width="80"></el-table-column>
          <!-- <el-table-column prop="name"
                           label="操作"
                           width="60">
            <el-button type="text"
                       size="mini"
                       @click="dialogVisible = true">编辑</el-button>
          </el-table-column>-->
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button type="text" @click="addKeyTip(scope.row.drugCode)">添加</el-button>

              <el-button type="text" @click="dialogVisible = true">查看</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="drugName" label="药品名称"></el-table-column>

          <el-table-column prop="cbrand" label="商品名"></el-table-column>
          <el-table-column label="药品类型" width="70">
            <template slot-scope="scope">
              <div v-if="scope.row.nameType==8">西药</div>
              <div v-else-if="scope.row.nameType==2">草药</div>
              <div v-else-if="scope.row.nameType==6">中成药</div>
            </template>
          </el-table-column>
          <el-table-column prop="highRisk" label="高危" width="70"></el-table-column>
          <el-table-column prop="highRiskText" label="高危提示内容"></el-table-column>
          <el-table-column prop="drugSpec" label="药品规格" width="100"></el-table-column>
          <el-table-column prop="compName" label="药品生产厂家"></el-table-column>
          <el-table-column prop="approvalCode" label="批准文号"></el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <!-- 添加提示信息dialog -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="45%" :before-close="handleClose">
      <el-card class="dialog-card">
        <div class="Card_body">
          <BaseSearchBarItem>
            <div slot="lable" style="float: right; margin-right: 20px;">药品编码:</div>
            <div slot="input">
              <el-input v-model="dialogData.drugName" disabled placeholder="请输入关键字" />
            </div>
          </BaseSearchBarItem>
        </div>
        <div class="Card_body">
          <BaseSearchBarItem>
            <div slot="lable" style="float: right; margin-right: 20px;">是否高危:</div>
            <div slot="input">
              <el-select v-model="dialogData.highRisk" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </div>
          </BaseSearchBarItem>
        </div>
      </el-card>
      <el-card class="dialog-card2" style="margin-top: 10px;height:280px">
        <div slot="header" class="Card_title">
          <span>重点提示(高危)</span>
        </div>
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          :autosize="{ minRows: 8, maxRows: 8}"
          v-model="dialogData.highRiskText"
        ></el-input>
      </el-card>

      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="danger">清除重点提示</el-button>
        <el-button size="mini" type="success">保存重点提示</el-button>
        <el-button size="mini" type="primary">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getHintMsg } from "@/api/rad";
export default {
  data() {
    return {
      queryInfo: {
        srm: "",
        pageList: 1,
        pageSize: 20
      },
      total: 0,
      tableData: [],
      dialogVisible: false,
      dialogData: {
        drugCode: "",
        highRiskText: "",
        highRisk: ""
      },
      options: [
        {
          value: 0,
          label: "否"
        },
        {
          value: 1,
          label: "是"
        }
      ]
    };
  },
  created: function() {
    this.getHintMsg();
  },
  methods: {
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getHintMsg();
    },

    handleCurrentChange(newPage) {
      this.queryInfo.pageList = newPage;
      this.getHintMsg();
    },
    handleClose(done) {
      done();
    },
    async getHintMsg() {
      let _this = this;
      let res = await this.$rad.getHintMsg({
        srm: _this.queryInfo.srm,
        page: _this.queryInfo.pageList,
        pageSize: _this.queryInfo.pageSize
      });
      this.tableData = res.rows;
      this.total = res.total;
      console.log(res.rows);
    },
    getSearchList() {
      this.getHintMsg();
    },
    clearEvent() {
      this.getHintMsg();
    },
    addKeyTip(drugCode) {
      this.dialogData.drugCode = drugCode;
      console.log(drugCode);
      this.dialogVisible = true;
    }
  }
};
</script>
<style scoped>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
/* dialog样式 */
.dialog-card >>> .el-card__body {
  padding: 0px 0px;
  width: 100%;
  height: 50px;
  display: flex;
  flex: 1;
  /* background-color: red; */
}
.el-card__body >>> .el-textarea {
  height: 210px;
}
</style>